﻿using SuperX.Common.Log;
using SuperX.Helper.ServiceResponse;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System;

namespace SuperX.DataCenterService.WebAPI
{
    public class ApiExceptionAttribute : ExceptionFilterAttribute
    {
        public override void OnException(ExceptionContext context)
        {
            Logger.Error($"执行 {context.RouteData.Values["service"] ?? ""}.{context.RouteData.Values["moduleAction"] ?? ""} 出现错误：");
            Logger.ErrorException(context.Exception);
            var res = ApiResponse<string>.Fail(context.Exception.Message);
            context.Result = new JsonResult(res);
            base.OnException(context);
        }
    }
}